How does this JavaScript/JQuery Syntax work: (function( window, undefined ) { })(window)?
Posted
by DKinzer
on Stack Overflow
See other posts from Stack Overflow
or by DKinzer
Published on 2010-04-26T18:58:59Z
Indexed on
2010/04/26
19:13 UTC
Read the original article
Hit count: 168
Have you ever taken a look under the hood at the JQuery 1.4 source code and noticed how it's encapsulated in the following way:
(function( window, undefined ) {
//All the JQuery code here
...
})(window);
I've read an article on JavaScript Namespacing and another one called "An Important Pair of Parens," so I know some about what's going on here.
But I've never seen this particular syntax before. What is that undefined
doing there? And why does window
need to be passed and then appear at the end again?
© Stack Overflow or respective owner